
import router from '@system.router'
export default {
  lastPage: '',
  onShow(self) {
    self.$app.setAppData('lastPage',self.$page&&self.$page.name)
    if (this.lastPage === self) {
      if(self.$app&&self.$app.$def&&self.$app.$def.pubsubModel){
        console.log('回到前台')
        self.$app.$def.pubsubModel.publish('comeFront', {
          type:1 // 1 前台  2 页面显示
        })
      }
    } else {
      this.lastPage = self
      if(self.$app&&self.$app.$def&&self.$app.$def.pubsubModel){
        self.$app.$def.pubsubModel.publish('comeFront', {
          type:2 // 1 前台  2 页面显示
        })
      }
    }
  },
  onHide(self) {
    if (router&&router.getState()&&router.getState().name === 'System.Web') {
      console.log('页面隐藏',this.lastPage)
      if(self.$app&&self.$app.$def&&self.$app.$def.pubsubModel){
        self.$app.$def.pubsubModel.publish('comeBackgroud', {
          type:2 // 1 后台  2 页面隐藏
        })
      }
      this.lastPage = null
    } else {
      let t = setTimeout(() => {
        if (this.lastPage === self) {
          console.log('退到后台')
          if(self.$app&&self.$app.$def&&self.$app.$def.pubsubModel){
            self.$app.$def.pubsubModel.publish('comeBackgroud', {
              type:1 // 1 后台  2 页面隐藏
            })
          }
        }
        clearTimeout(t)
      }, 500)
    }
  }
}